package org.opens.common.api;

public class Result<T> {

    private static final long serialVersionUID = 151641579L;

    public static final Integer SUCCESS_CODE = 200;

    public static final Integer ERROR_CODE = 201;

    private Integer code;

    private T data;

    private String message;

    public Result() {
    }

    public static <D> Result<D> success(D data, String message) {
        Result<D> result = new Result<>();

        result.data = data;
        result.code = SUCCESS_CODE;
        result.message = message;

        return result;
    }

    public static <D> Result<D> success(D data) {
        return success(data, "");
    }

    public static <D> Result<D> error(D data, String message) {
        Result<D> result = new Result<>();

        result.code = ERROR_CODE;
        result.data = data;
        result.message = message;

        return result;
    }

    public static <D> Result<D> error(D data) {
        return error(data, "");
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

}